<template>
  <div class="tabs flex">
    <div
      :class="['tabs-list', 'flex', activeIndex == index ? 'active' : '']"
      v-for="(item, index) in data"
      @click="handleClick(index)"
    >
      <span class="tab-list-title">{{ item.title }}</span>
      <span class="tab-list-count" @click.stop="handleNumClick(item)"
        ><b>{{ item.count }}</b
        ><span class="unit">条</span></span
      >
    </div>
  </div>
</template>

<script>
export default {
  props: {
    data: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      activeIndex: 0,
    };
  },
  methods: {
    handleClick(index) {
      this.activeIndex = index;
      this.$emit("handleClick", index);
    },
    handleNumClick(param) {
      this.$emit("handleNumClick", param);
    },
  },
};
</script>

<style lang="scss" scoped>
.tabs {
  width: 100%;
  flex-wrap: wrap;
  text-align: left;
  justify-content: space-around;
  .tabs-list {
    cursor: pointer;
    width: 47%;
    padding: 1rem;
    border-bottom: 2px solid transparent;
    &.active {
      border-bottom: 2px solid #000 !important;
      border-image: linear-gradient(
          to right,
          rgba(5, 142, 184, 0.2),
          rgba(2, 231, 243, 0.8),
          rgba(2, 143, 181, 0.1)
        )
        1;
    }
    .tab-list-title {
      flex: 1;
      font-szie: 1.4rem;
      font-weight: bold;
    }
    .tab-list-count {
      b {
        font-size: 1.6rem;
        margin-right: 1rem;
      }
    }
    &:nth-of-type(1) {
      position: relative;
      border-left: 0.3rem solid rgba(2, 231, 243, 1);
      background-image: linear-gradient(
        to right,
        rgba(2, 231, 243, 0.4),
        transparent
      );
      &:before {
        position: absolute;
        left: -1.8rem;
        content: "";
        display: block;
        width: 0.5rem;
        height: 0.1rem;
        border-left: 0.5rem solid transparent;
        border-top: 0.5rem solid transparent;
        border-right: 0.5rem solid rgba(2, 231, 243, 1);
        border-bottom: 0.5rem solid transparent;
      }
    }

    &:nth-of-type(2) {
      position: relative;
      border-left: 0.3rem solid rgba(59, 139, 255, 1);
      background-image: linear-gradient(
        to right,
        rgba(59, 139, 255, 0.4),
        transparent
      );
      &:before {
        position: absolute;
        left: -1.8rem;
        content: "";
        display: block;
        width: 0.5rem;
        height: 0.1rem;
        border-left: 0.5rem solid transparent;
        border-top: 0.5rem solid transparent;
        border-right: 0.5rem solid rgba(59, 139, 255, 1);
        border-bottom: 0.5rem solid transparent;
      }
    }
  }
}
</style>
